package com.btrh.util;

import java.io.Serializable;

/**
 * @author zyy
 * @date 2020/2/18 16:57
 * @description
 */

public class R implements Serializable{

    private int code;
    private String message;
    private Object data;


    public R() {

    }


    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }


    /**
     * 未定义
     * 成功
     * @return 200 操作成功
     */
    public static R success(){
        R R = new R();
        R.setCode(ResponseCode.SUCCESS.getCode());
        R.setMessage(ResponseCode.SUCCESS.getMessage());
        return R;
    }

    /**
     * 成功
     * @param data 自定义data
     * @return 200 操作成功 data
     */
    public static R success(Object data){
        R R = new R();
        R.setMessage(ResponseCode.SUCCESS.getMessage());
        R.setCode(ResponseCode.SUCCESS.getCode());
        R.setData(data);
        return R;
    }

    /**
     * 未定义
     * 201 操作失败
     * @return 201 操作失败
     */
    public static R failed(){
        R R = new R();
        R.setCode(ResponseCode.FAILED.getCode());
        R.setMessage(ResponseCode.FAILED.getMessage());
        return  R;
    }


    /**
     * 自定义：
     * 该方法指定201code码，错误信息自定义 不带data返回值
     * @param message
     * @return 201 “自定义错误信息”
     */
    public static R failed(String message){
        R R = new R();
        R.setCode(ResponseCode.FAILED.getCode());
        R.setMessage(message);
        return  R;
    }

    /**
     * 未定义
     * 返回失败  错误枚举对象  如201 操作失败
     * @param data
     * @return 201 操作失败 data
     */
    public static R failed(Object data){
        R R = new R();
        R.setCode(ResponseCode.FAILED.getCode());
        R.setMessage(ResponseCode.FAILED.getMessage());
        R.setData(data);
        return  R;
    }


}
